package com.example.rabbitmqdemo.hellorabbitmq.simplest;

import cn.hutool.core.util.StrUtil;
import com.example.rabbitmqdemo.hellorabbitmq.CommonUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.concurrent.TimeoutException;

@Slf4j
public class ProducerSimplest {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = CommonUtil.getFactory();
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("simplest", true, false, false, null);
        String msg = StrUtil.format("-- simplest {}", LocalDateTime.now());
        channel.basicPublish("", "simplest", null, msg.getBytes(StandardCharsets.UTF_8));
        log.info("发送完成 msg {}", msg);
        channel.close();
        connection.close();

    }
}
